import Vue from "vue";
import Vuex from "vuex";
import api from "@/plugins/api";

Vue.use(Vuex);

function load(component) {
  return () => import(`@/views/Main/${component}`);
}

export default new Vuex.Store({
  state: {
    menu: [
      { path: "/", name: "Home", component: load("Home"), meta: { title: "首页", icon: "el-icon-s-home" } },
      { path: "/EditDoc", name: "EditDoc", component: load("EditDoc"), meta: { title: "添加文档", icon: "el-icon-document" } },
      // { path: "/DocumentCopy", name: "DocumentCopy", component: load("DocumentCopy"), meta: { title: "文档管理", icon: "el-icon-s-management" } },
      { path: "/Document", name: "Document", component: load("Document"), meta: { title: "文档管理", icon: "el-icon-s-management" } },
      { path: "/Classify", name: "Classify", component: load("Classify"), meta: { title: "类目管理", icon: "el-icon-s-order" } },
      { path: "/Config", name: "Config", component: load("Config"), meta: { title: "设置", icon: "el-icon-setting" } },
    ],
    classify: [],
  },
  getters: {},
  mutations: {
    getMenu(state) {
      api.get("/Classify/List").then(({ data }) => {
        Vue.set(state, "classify", data);
        // let index = state.menu.findIndex(v => v.name == "Document");
        // let children = data.map(v => {
        //   return {
        //     name: v.name,
        //     path: "/Document",
        //     component: resolve => require([`@/views/Main/Document.vue`], resolve),
        //     children: v.tag,
        //     meta: { title: v.title, _id: v._id },
        //   };
        // });
        // Vue.set(state.menu[index], "children", children);
      });
    },
  },
  actions: {},
  modules: {},
});
